<!DOCTYPE html>
<html>
<head>
    <title>测试</title>
</head>
<body>
<div id="show"></div>
<input id="msg" type="text" placeholder="请输入弹幕">
<button onclick="sendMessage()">发送</button>
<script type="text/javascript">
    //创建ws对象
    let websocket = new WebSocket("ws://192.168.114.22:8888/ws");
    if(websocket){
        //支持ws，设置接收消息回调
        websocket.onmessage = function(){
            console.log(event.data);
        };
    }else{
        alert("浏览器不支持WebSocket")
    }
    //发送消息
    function sendMessage(){
        let msg = document.getElementById("msg").value;
        websocket.send(msg);
    }
</script>
</body>
</html>
